package cn.edu.scau.cmi.liyunlin.Singleton;

import java.util.HashSet;
import java.util.Set;

public class Marshal {
	
	private String name;
	private static Set<Marshal> marshalSet = new HashSet<>();
	private static Set<String> nameList = new HashSet<>();
	private static Marshal marshal;
	
	private Marshal(String name){
		this.name = name;
	}
	
	public static Marshal getInstance(String name){// 用于new Marshal实例
		if(marshalSet.size()<10){
			marshal = new Marshal(name);
			marshalSet.add(marshal);
		}
		return marshal;
	}

	public static String judgeName(String name) {// 用于判断名字是否重复，判断是否已创建十个元帅
		if(nameList.size()<10){
			if(nameList.contains(name)) {
				return (name + "元帅已经创建了!\n");
			} else {
				nameList.add(name);
			}
		}else {
			return ("您已经创建了十个元帅了！\n");
		}
		return "1";
	}

	public void setName(String name) {
		this.name = name;
	}
	
}
